package com.webcat.controller;

import com.webcat.entity.AiResponse;
import com.webcat.entity.SseResponse;
import com.webcat.service.QuestionService;
import com.webcat.service.ToolService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/tool")
@Slf4j
public class ToolChatController {

    @Resource
    private ToolService toolService;

    @GetMapping(value = "/start")
    public AiResponse<String> start() {
        return AiResponse.success(toolService.start());
    }

    @GetMapping(value = "/streamChat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<SseResponse<Object>> streamChat(@RequestParam("chatId") String chatId, String message, String toolId) {
        return toolService.streamChat(chatId, message, toolId, false);
    }
}
